package br.com.fogas.medicao.activity.dialog;

import br.com.fogas.medicao.R;
import br.com.fogas.medicao.application.Constants;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class DialogMenuFoto extends DialogFragment {
	
	private DialogMenuFotoListener listener;
	private Button btnVisualizar;
	private Button btnCapturar;
	private Button btnCancelar;
	private boolean isCapturar = true;
	private boolean isVisualizar = true;
	
	public interface DialogMenuFotoListener {
		public void onVisualizarClick(DialogFragment dialog);
		public void onCapturarClick(DialogFragment dialog);
	}
	
	public static DialogMenuFoto newInstance(DialogMenuFotoListener listener) {
		return new DialogMenuFoto()
		.setListener(listener);
	}
	
	public DialogMenuFoto setListener(DialogMenuFotoListener listener) {
		this.listener = listener;
		return this;
	}
	
	public DialogMenuFoto showDialog(FragmentManager fragmentManager) {
		show(fragmentManager, Constants.DIALOG_ALERT);
		return this;
	}
	
	public DialogMenuFoto setCapturar(boolean isCapturar) {
		this.isCapturar = isCapturar;
		return this;
	}
	
	public DialogMenuFoto setVisualizar(boolean isVisualizar) {
		this.isVisualizar = isVisualizar;
		return this;
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		LayoutInflater inflater = getActivity().getLayoutInflater();
		View layout = inflater.inflate(R.layout.menu_foto, null); 
		
		this.btnVisualizar = (Button) layout.findViewById(R.id.btnVisualizar);
		this.btnVisualizar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				listener.onVisualizarClick(DialogMenuFoto.this);
			}
		});
		if(!isVisualizar)
			this.btnVisualizar.setVisibility(View.GONE);
		
		this.btnCapturar = (Button) layout.findViewById(R.id.btnCapturar);
		this.btnCapturar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				listener.onCapturarClick(DialogMenuFoto.this);
			}
		}); 
		if(!isCapturar)
			this.btnCapturar.setVisibility(View.GONE);

		this.btnCancelar = (Button) layout.findViewById(R.id.btnCancelar);
		this.btnCancelar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				DialogMenuFoto.this.dismiss();
			}
		}); 
		
		Dialog dialog = new AlertDialog.Builder(getActivity())
		        .setView(layout)
				.setTitle(R.string.simulacao_menu_foto)
				.create();
		 
		return dialog;
	}
}
